package cn.szabadsag.quartz.service.impl;

import cn.szabadsag.quartz.domain.QuartzJobInfo;
import cn.szabadsag.quartz.job.MainJob;
import cn.szabadsag.quartz.service.IQuartzService;
import cn.szabadsag.utils.QuartzUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Service;

/**
 * @author yangcong
 * @date 2022年03月21日 12:55
 * @since
 */
@Service
public class QuartzServiceImpl implements IQuartzService {

    @Autowired
    private SchedulerFactoryBean factoryBean;

    @Override
    public void addJob(QuartzJobInfo info) {
        QuartzUtils.addJob(factoryBean.getScheduler(),info.getJobName(),
                MainJob.class,info,info.getCronj());

    }

    @Override
    public void delJob(String jobName) {

        QuartzUtils.removeJob(factoryBean.getScheduler(),jobName);
    }
}

